/*
* Copyright (c) 2008-2011, Thomas Handorf, Nils Christian
* 
* This file is part of libScopes.
* libScopes is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* libScopes is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public License
* along with libScopes.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "netstruct.h"

NetStruct::NetStruct(){
	IN=new VVS();
	OUT=new VVS();
	INH=new VVS();
   CMPI=new VVS();
   CAT=new VVS();
   PRP=new VVS();
   INST=new VVF();
	OUTST=new VVF();
	CSUC=new VVS();
	CPRE=new VVS();
   FAM=new VVS();
   FCN=new VVS();
   REV=new VC();
   names=new array<std::string>;
   hasFam=false;
	numR=0;
	numC=0;
	nextToAdd=0;;
	refCount=0;
}
NetStruct::NetStruct(size_type nr, size_type nc){
	numR=0;
	numC=0;
	IN=new VVS();
	OUT=new VVS();
	INH=new VVS();
   CMPI=new VVS();
   CAT=new VVS();
   PRP=new VVS();
   INST=new VVF();
	OUTST=new VVF();
	CSUC=new VVS();
	CPRE=new VVS();
   FAM=new VVS();
   FCN=new VVS();
   REV=new VC();
   hasFam=false;
   names=new array<std::string>;
   resize(nr,nc);
	nextToAdd=0;;
	refCount=0;
}
NetStruct::NetStruct(const NetStruct& ns2){
	size_type i;
	numR=ns2.numR;
	numC=ns2.numC;
	IN=new VVS(numR);
	OUT=new VVS(numR);
	INH=new VVS(numR);
	CMPI=new VVS(numR);
   CAT=new VVS(numR);
   PRP=new VVS(numR);
   INST=new VVF(numR);
	OUTST=new VVF(numR);
	CSUC=new VVS(numC);
	CPRE=new VVS(numC);
   FAM=new VVS(numC);
   FCN=new VVS(numC);
   hasFam=ns2.hasFam;
   for (i=0;i<numR;i++){
		(*IN)[i]=new VS((*(*ns2.IN)[i]));
		(*OUT)[i]=new VS((*(*ns2.OUT)[i]));
		(*INH)[i]=new VS((*(*ns2.INH)[i]));
		(*CMPI)[i]=new VS((*(*ns2.CMPI)[i]));
      (*CAT)[i]=new VS((*(*ns2.CAT)[i]));
      (*PRP)[i]=new VS((*(*ns2.PRP)[i]));
      (*INST)[i]=new VF((*(*ns2.INST)[i]));
		(*OUTST)[i]=new VF((*(*ns2.OUTST)[i]));
	}			
	for (i=0;i<numC;i++){
		(*CSUC)[i]=new VS((*(*ns2.CSUC)[i]));
		(*CPRE)[i]=new VS((*(*ns2.CPRE)[i]));
      (*FAM)[i]=new VS((*(*ns2.FAM)[i]));
      (*FCN)[i]=new VS((*(*ns2.FCN)[i]));
   }
	REV=new VC((*ns2.REV));
   names=new array<std::string>(*(ns2.names));
	nextToAdd=ns2.nextToAdd;
	refCount=0;
}
NetStruct::~NetStruct(){
	size_type i;
#ifdef DEBUG	
	printf("NetStruct: destroy: realinks\n");fflush(stdout);
#endif
	for (i=0;i<numR;i++){
		delete (*IN)[i];
		delete (*OUT)[i];
		delete (*INH)[i];
		delete (*CMPI)[i];
      delete (*CAT)[i];
      delete (*PRP)[i];
      delete (*INST)[i];
		delete (*OUTST)[i];
	}
#ifdef DEBUG	
	printf("NetStruct: destroy: reaarray\n");fflush(stdout);
#endif
	delete IN;IN=NULL;
	delete OUT;OUT=NULL;
	delete INH;INH=NULL;
	delete CMPI;CMPI=NULL;
   delete CAT;CAT=NULL;
   delete PRP;PRP=NULL;
   delete INST;INST=NULL;
	delete OUTST;OUTST=NULL;
	delete REV;REV=NULL;
#ifdef DEBUG	
	printf("NetStruct: destroy: comlinks\n");fflush(stdout);
#endif
	for (i=0;i<numC;i++){
		delete (*CSUC)[i];
		delete (*CPRE)[i];
      delete (*FAM)[i];
      delete (*FCN)[i];
   }
#ifdef DEBUG	
	printf("NetStruct: destroy: comarray\n");fflush(stdout);
#endif
	delete CSUC;CSUC=NULL;
	delete CPRE;CPRE=NULL;
   delete FAM;FAM=NULL;
   delete FCN;FCN=NULL;
   delete names;names=NULL;
}
void NetStruct::resize(size_type nr, size_type nc){
	size_type i;
//	printf("NetStruct: resize: (%ld,%ld) -> (%ld,%ld)\n",numR,numC,nr,nc);fflush(stdout);
   for (i=nr;i<numR;i++){
      delete (*IN)[i];
      delete (*OUT)[i];
      delete (*INH)[i];
      delete (*CMPI)[i];
      delete (*CAT)[i];
      delete (*PRP)[i];
      delete (*INST)[i];
      delete (*OUTST)[i];
   }
   IN->resize(nr);
   OUT->resize(nr);
   INH->resize(nr);
   CMPI->resize(nr);
   CAT->resize(nr);
   PRP->resize(nr);
   INST->resize(nr);
   OUTST->resize(nr);
   REV->resize(nr);
   for (i=numR;i<nr;i++){
      (*IN)[i]=new VS();
      (*OUT)[i]=new VS();
      (*INH)[i]=new VS();
      (*CMPI)[i]=new VS();
      (*CAT)[i]=new VS();
      (*PRP)[i]=new VS();
      (*INST)[i]=new VF();
      (*OUTST)[i]=new VF();
   }
   numR=nr;

   for (i=nc;i<numC;i++){
      delete (*CSUC)[i];
      delete (*CPRE)[i];
      delete (*FAM)[i];
      delete (*FCN)[i];
   }

   CSUC->resize(nc);
   CPRE->resize(nc);
   FAM->resize(nc);
   FCN->resize(nc);
   for (i=numC;i<nc;i++){
      (*CSUC)[i]=new VS();
      (*CPRE)[i]=new VS();
      (*FAM)[i]=new VS();
      (*FCN)[i]=new VS();
   }
   numC=nc;
	names->resize(nc);
}
/*NetStruct::NetStruct(string &str){
	size_type pos=0;
	initFromString(str,pos);
}
NetStruct::NetStruct(string &str,size_type &pos){
	initFromString(str,pos);
}*/

